<%--
  Created by IntelliJ IDEA.
  User: Lenovo
  Date: 2023/11/11
  Time: 19:00
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>Insert title here!</title>
</head>
<body>
<jsp:useBean id="calculater" class="jspSamples.unit5.javaBeanSamples.shixun5_1Calculater" scope="request"></jsp:useBean>
<jsp:setProperty name="calculater" property="*"></jsp:setProperty>
<form action="shixun5-1index.jsp" method="get">
    <hr align="left" style="width:400px;">
    计算结果是：
    <span>
        <%
            if(request.getParameter("operator") != null){
                String operator = request.getParameter("operator");
                int oper = Integer.parseInt(operator);
                if(oper == 4 && calculater.getNum2() == 0){
                    out.print("出错，除数不能为0");
                }else{
        %>
        <%=calculater.getNum1()%>
        <%
                    if(oper == 1) out.print("+");
                    if(oper == 2) out.print("-");
                    if(oper == 3) out.print("*");
                    if(oper == 4) out.print("/");
        %>
        <%=calculater.getNum2()%>
        =
        <%=calculater.getResult()%>
        <%
                }

            }
        %>
    </span>
<!--表达式显示-->
    <hr align="left" style="width:400px;">
    <div align="left" style="width:400px;">
        <p align="center">
            简单计算器
        </p>
        第一个参数：<input type="text" name="num1"/><br>
        <div style="padding-left:100px;">
            <select name="operator">
                <option value="1">+</option>
                <option value="2">-</option>
                <option value="3">*</option>
                <option value="4">/</option>
            </select>
        </div>
        第二个参数：<input type="text" name="num2"/><br>
        <input type="submit" value="计算" style="margin-left:100px;">
    </div>
</form>
</body>
</html>
